<%--
  Created by IntelliJ IDEA.
  User: HP
  Date: 2020/11/13
  Time: 16:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册|图书管理系统</title>
    <script src="${pageContext.request.contextPath}/js/jquery-3.5.1.min.js"></script>
    <script type="text/javascript">
        function register() {
            var  username=$('#username').val().trim();
            var password=$('#pwd1').val().trim();
            $.ajax({
                url:'CheckSameUserServlet',
                data:{'username':username},
                type:'get',
                success:function (res) {
                    if (!(res=='success')){
                        alert(res);
                    }else {
                        var pwd2 = $('#pwd2').val().trim();
                        if (!(password===pwd2)){
                            alert("密码不一致");
                            return false;
                        }

                        $.ajax({
                            url:'RegisterServlet',
                            data: {'username':username,'password':password},
                            type: 'post',
                            success:function (res) {
                            if(res=='success'){
                                alert("注册成功");
                            }else {
                                alert("注册失败");
                            }
                            }
                        })
                    }

                }

            })

        }
    </script>
</head>
<body>
<div align="center">
    <h1>注&nbsp;&nbsp;册</h1>
        <table>
            <tr>
                <td>用户名: </td>
                <td><input type="text" id="username" name="username"></td>
            </tr>
            <tr>
                <td>密码: </td>
                <td><input type="password" id="pwd1" name="pwd1"></td>
            </tr>
            <tr>
                <td>确认密码： </td>
                <td><input type="password" id="pwd2" name="pwd2"></td>
            </tr>
            <tr>
                <td colspan="2"><button onclick=register()>注册</button></td>
            </tr>
        </table>

</div>


</body>
</html>
